package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 用户提交订单，往订单表中插入订单数据
     * @param orders
     */
    void submit(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据id查询订单表信息
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getByOrders(Long id);

    @Delete("delete from orders where id = #{id}")
    void delete(Long id);

    Page<Orders> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status= #{status}")
    Integer countByOrdersStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime time);

    Double sumByMap(Map map);

    /**
     * 用户统计
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 查询销量排名top10接口k
     * @param beginTime
     * @param endTime
     * @return
     */
    List<GoodsSalesDTO> getTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
